package com.attcatstudy.Thread;

/**
 * @author attcat
 * ---做一个有趣的程序员
 * @date 2022-10-31 20:13
 * @description 等待调用join方法的线程结束之后，程序再继续执行，一般用于等待异步线程执行完结果之
 * 后才能继续运行的场景。
 */
public class ThreadJoinDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t begin");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t  end ");
            }
        });

        t.start();
        t.join();////主线程等待线程t 线程执行完
        System.out.println("Main finished");

    }
}
